package com.sleepcamel.exporter.mappingGenerator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.sleepcamel.rest.domain.JavaClass;
import com.sleepcamel.rest.domain.method.RESTMethod;
import com.sleepcamel.rest.domain.method.RESTMethodType;

public abstract class BaseMappingToMethodGenerator {

	protected JavaClass javaClass;
	protected Map<RESTMethodType, BaseMappingGenerator> mappingGenerators = new HashMap<RESTMethodType, BaseMappingGenerator>();

	public BaseMappingToMethodGenerator() {
		registerMappingGenerators();
	}
	
	public Collection<? extends RESTMethod> generateMethods(RESTMethodType restMethodType){
		if ( !mappingGenerators.containsKey(restMethodType) )
			return new ArrayList<RESTMethod>();
		
		BaseMappingGenerator iMappingGenerator = mappingGenerators.get(restMethodType);
		iMappingGenerator.setJavaClass(javaClass);
		return iMappingGenerator.generate();
	}

	protected void registerMappingGenerator(RESTMethodType methodType, BaseMappingGenerator mappingGenerator){
		mappingGenerators.put(methodType, mappingGenerator);
	}
	
	public void setJavaClass(JavaClass domainClass){
		javaClass = domainClass;
	}
	
	abstract protected void registerMappingGenerators();
}
